home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / cmdialog / modcd.bas < prev   
BASIC Source File  |  1995-07-03  |  2KB  |  54 lines

  1. 'This module contains the OpenFile & CloseFile Subroutines.
  2.  
  3. Global Const CC_RGBINIT = &H1& ' This is the Constant for
  4.                                ' the Flags property of the
  5.                                ' COLOR Common Dialog.
  6.  
  7. Global Const CF_BOTH = &H3&    ' This is the Constant for
  8.                                ' the Flags property of the
  9.                                ' FONTS Common Dialog. You
  10.                                ' can also use:
  11.                                ' CF_SCREENFONTS (&H1&)
  12.                                ' or CF_PRINTERFONTS (&H2&)
  13.  
  14.  
  15. Sub CloseFile (Filename As String)
  16. Dim F As Integer
  17. On Error GoTo CloseError                ' If there is an error, display the error message below.
  18.     
  19.     If Dir(Filename) <> "" Then         ' File already exists, so ask if overwriting is desired.
  20.         response = MsgBox("Overwrite existing file?", MB_YESNO + MB_QUESTION + MB_DEFBUTTON2)
  21.         If response = IDNO Then Exit Sub
  22.     End If
  23.     F = FreeFile
  24.     Open Filename For Output As F       ' Otherwise, open the file name for output.
  25.     Print #F, frmCD!txtCD.Text    ' Print the current text to the opened file.
  26.     Close F                             ' Close the file
  27.     Filename = "Untitled" ' Reset the caption of the main form
  28.     Exit Sub
  29. CloseError:
  30.     MsgBox "Error occurred trying to close file, please retry.", 48
  31.     Exit Sub
  32. End Sub
  33.  
  34. Sub OpenFile (Filename As String)
  35. Dim F As Integer
  36.     ' Instruction to open a file.
  37.     If "Project Name Here: " + Filename = frmCD.Caption Then
  38.         Exit Sub
  39.     Else
  40.         On Error GoTo ErrHandler
  41.             F = FreeFile
  42.             Open Filename For Input As F
  43.             frmCD!txtCD.Text = Input$(LOF(F), F)
  44.             Close F
  45.             frmCD.Caption = "Project Name Here: " + Filename
  46.             Exit Sub
  47.     End If
  48. ErrHandler:
  49.     MsgBox "Error occurred while trying to open file, please retry.", 48, "Project Name Here"
  50.     Close F
  51.     Exit Sub
  52. End Sub
  53.  
  54.